<template>
  <div style="overflow: auto; padding: 0 10px">
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane v-if="project.DSSP_HasBefore" :key="1" label="施工前" :name="1"></el-tab-pane>
      <el-tab-pane v-if="project.DSSP_HasAfoot" :key="2" label="施工中" :name="2"></el-tab-pane>
      <el-tab-pane v-if="project.DSSP_HasAfter" :key="3" label="施工后" :name="3"></el-tab-pane>
      <div class="header">
        <el-form inline>
          
          <el-button type="primary" @click="addSurveyVis = true">
            添加花名册
          </el-button>
          <el-button type="primary"  v-loading.fullscreen.lock="fullscreenLoading" element-loading-text="正在导出，请稍后"
              element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" 
                @click="GetRoster()">
                导出花名册
          </el-button>


          <el-button type="primary" @click="projectStepVis = true">
            勘查名单管理
          </el-button>
          <el-button  style="margin-right: 10px" @click="toImport(prjId)">
            导入花名册
          </el-button>
          <el-button v-if="activeName == 2" style="margin-right: 10px" @click="doImportBeforeSurveyList(2)">
            导入施工前花名册
          </el-button>

          <el-button v-if="activeName == 3" style="margin-right: 10px" @click="doImportBeforeSurveyList(3)">
            导入施工前花名册
          </el-button>
          <el-button v-if="activeName == 3" style="margin-right: 10px" @click="doImportAfootSurveyList()">
            导入施工中花名册
          </el-button>

          <el-badge :value="undoneCount" class="item">
            <el-button @click="toSurveyModify">修改意见</el-button>
          </el-badge>
        </el-form>
        <el-form inline style="margin-top: 20px">
          <el-form-item label="勘察情况">
            <el-checkbox v-model="isSurveyMap" @change="isSurveyMapChange" :label="isSurveyMap?'勘察名单':'全部花名册'"></el-checkbox>
          </el-form-item>
          <el-form-item  v-if="isSurveyMap" label="勘察人员">
            <el-select style="width: 300px" v-model="selectEmpId" filterable remote reserve-keyword placeholder="请输入关键词"
              :remote-method="doGetEmployees" :loading="loading">
              <el-option label="全部" :value="0">
                全部
              </el-option>
              <el-option v-for="item in employees" :key="item.ECV_TargetID" :label="item.USR_Name"
                :value="item.EMP_ID">
                {{ item.USR_Name }}
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <el-form inline style="margin-top: 20px">
          <el-form-item label="姓名">
            <el-input v-model="searchName"></el-input>
          </el-form-item>
          <el-form-item style="margin-left: 20px;" label="未完成审核">
            <el-checkbox v-model="isInfoNoAudit" label="定位信息"></el-checkbox>
            <el-checkbox v-model="isPlaneNoAudit" label="户型图"></el-checkbox>
            <el-checkbox v-model="isSurveyNoAudit" label="勘查信息"></el-checkbox>
          </el-form-item>


          <el-button @click="doGetSurveys()">搜索</el-button>
        </el-form>
      </div>
      <div class="container">
        <el-table :data="surveys">
          <el-table-column label="编号" prop="DSSV_No"></el-table-column>
          
          <el-table-column label="姓名" prop="DSSV_Name"></el-table-column>
          <el-table-column label="村组" prop="DSSV_Village"></el-table-column>
          <el-table-column label="楼层" prop="DSSV_Floor"></el-table-column>
          <el-table-column label="结构类型" prop="DSSV_Structure">
            <template slot-scope="scope">
              <span v-for="structure in scope.row.DSSV_Structure.split(',')" :key="structure">
                {{ structures[structure] }}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="距离范围" prop="DSSV_Distance"></el-table-column>
          
          <el-table-column label="定损金额" prop="DSSV_ConfirmMoney"></el-table-column>
          <el-table-column label="报告日期" prop="DSSV_ReportDate">
            <template slot-scope="scope">
              <span>
                {{
                  scope.row.DSSV_ReportDate == null
                    ? '未确定'
                    : scope.row.DSSV_ReportDate.split(' ')[0]
                }}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="支付金额" prop="DSSV_PayMoney"></el-table-column>
          <el-table-column label="更新日期" prop="DSSV_UpdateDate">
            <template slot-scope="scope">
              <span>
                {{
                  scope.row.DSSV_UpdateDate == null
                    ? '未确定'
                    : scope.row.DSSV_UpdateDate.split(' ')[0]
                }}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="勘查阶段" v-if="isSurveyMap" >
            <template slot-scope="scope">
            <span>
            {{surveySteps[scope.row.DSSLM_SurveyCount]}}
            </span>
          </template>
          </el-table-column>
          <el-table-column  v-if="isSurveyMap" label="分配人员" >
            <template slot-scope="scope">
              <span v-for="op in scope.row.ops">
              {{
                  op
                }} 
              </span>
            </template>
          </el-table-column>
          <el-table-column  v-if="isSurveyMap" label="完成人员" >
            <template slot-scope="scope">
              <span>
              {{
                  scope.row.USR_Name==null?'未勘察':scope.row.USR_Name
                }}
              </span>
            </template>
          </el-table-column>
          
          <el-table-column width="180" label="操作">
            <template slot-scope="scope">
              <el-button type="primary" icon="el-icon-edit" circle @click="toDetailPage(scope.row)"></el-button>
              <el-button type="primary" icon="el-icon-s-check" circle
                @click="toSurveyAudit(scope.row.DSSV_ID)"></el-button>
              <el-button type="primary" icon="el-icon-download" v-loading.fullscreen.lock="fullscreenLoading" element-loading-text="正在导出，请稍后"
              element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" circle
                @click="outputImages(scope.row.DSSV_ID,scope.row.DSSV_Name)"></el-button>
              <el-button type="danger" icon="el-icon-delete" circle
                @click="doRemoveSurveyStep(scope.row.DSSV_ID)"></el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination :current-page.sync="pageIndex" :total="total" :page-size.sync="pageSize" :page-sizes="[10, 20]"
          @size-change="
            (val) => {
              pageSize = val
              doGetSurveys()
            }
          " @current-change="doGetSurveys()" />
      </div>
    </el-tabs>

    <el-dialog title="勘查名单管理" width="70%" :visible.sync="projectStepVis">
      <div style="height: 50px; line-height: 50px; display: flex">
        <el-button @click="addSurveyListVis = true" type="primary">
          添加勘查名单
        </el-button>
        
      </div>
      <el-table :data="surveyList">
        <el-table-column width="60" label="序号" prop="DSSL_ID"></el-table-column>
        <el-table-column width="200" label="名称" prop="DSSL_FileName"></el-table-column>
        <el-table-column width="100" label="项目阶段">
          <template slot-scope="scope">
            <span>
              {{
                scope.row.DSSL_StepID == 1
                  ? '施工前'
                  : scope.row.DSSL_StepID == 2
                    ? '施工中'
                    : '施工后'
              }}
            </span>
          </template>
        </el-table-column>

        <el-table-column width="100" label="创建人" prop="USR_Name"></el-table-column>
        <el-table-column width="120" label="创建时间" prop="DSSL_CreateDate">
          <template slot-scope="scope">
            <span>
              {{
                scope.row.DSSL_CreateDate == null
                  ? ''
                  : scope.row.DSSL_CreateDate.split(' ')[0]
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="勘查人员">
          <template slot-scope="scope">
            <el-tag v-for="user in scope.row.opUsers" :key="user.USR_Name" closable @click="editSurveyOp(user)"
              @close="doDeleteSurveyOpUser(user.DSSOU_ID)">
              {{ user.USR_Name }}
            </el-tag>
            <el-button @click="
              selectOp = {}

            addSurveyOpVis = true
            isUpdateSurveyOp = false
            selectListID = scope.row.DSSL_ID
              " type="primary" style="margin-left: 10px" icon="el-icon-plus" circle></el-button>
          </template>
        </el-table-column>
        <el-table-column width="100" label="操作">
          <template slot-scope="scope">
            <el-button @click="doDeleteSurveyList(scope.row.DSSL_ID)" type="primary">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="projectStepVis = false">
          确定
        </el-button>
      </div>
    </el-dialog>

    <el-dialog title="导入勘察名单" :visible.sync="addSurveyListVis">
      <el-form ref="form"  label-width="140px">
        <el-form-item label="勘察次数">
            <el-select v-model="surveyStep" placeholder="请选择">
              <el-option
                :key="1" label="首勘":value="0">
              </el-option>
              <el-option
                :key="2" label="复勘":value="1">
              </el-option>
              <el-option
                :key="3" label="二次复勘":value="2">
              </el-option>

            </el-select>
            <el-upload v-loading.fullscreen.lock="fullscreenLoading" element-loading-text="正在导入，请稍后"
          element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" ref="upload"
          :on-success="handleListSuccess" :data="{ stepId: this.activeName, prjId: this.prjId,surveyStep: this.surveyStep }"
          :action="uploadListPath" :file-list="surveyListFiles" :headers="myHeaders" :limit="1">
          <el-button slot="trigger" size="small" type="primary">
            导入勘查名单
          </el-button>
        </el-upload>
          </el-form-item>
          
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addSurveyListVis =false
        surveyListFiles=[]">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="新增勘查记录" :visible.sync="addSurveyVis">
      <el-form ref="form" :model="addSurvey" label-width="80px">
        <!--<el-form-item label="勘查阶段"  required>
          <el-select v-model="addSurvey.DSSV_StepID" placeholder="请选择">
            <el-option
              v-for="item in selectSteps"
              :key="item.DSPJS_ID"
              :label="item.DSPJS_ProjectStepName"
              :value="item.DSPJS_ID"
            ></el-option>
          </el-select>
        </el-form-item>-->
        <el-form-item label="户主姓名" required>
          <el-input v-model="addSurvey.DSSV_Name"></el-input>
        </el-form-item>
        <el-form-item label="村组">
          <el-input v-model="addSurvey.DSSV_Village"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="addSurvey.DSSV_Phone"></el-input>
        </el-form-item>
        <el-form-item label="身份证号">
          <el-input v-model="addSurvey.DSSV_IDCard"></el-input>
        </el-form-item>
        <el-form-item label="是否代签">
          <el-switch v-model="addSurvey.DSSV_IsReplaceSign"></el-switch>
        </el-form-item>
        <el-form-item v-if="addSurvey.DSSV_IsReplaceSign == true" label="代签人">
          <el-input v-model="addSurvey.DSSV_ReplaceSignName"></el-input>
        </el-form-item>
        <el-form-item v-if="activeName != 1" label="减去炮前">
          <el-switch v-model="isMimus"></el-switch>
        </el-form-item>
        <el-form-item label="建筑结构">
          <el-select v-model="addSurvey.DSSV_Structure" multiple placeholder="请选择">
            <el-option v-for="(value, key, index) in structures" :key="index" :label="value" :value="key"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="层数">
          <el-input v-model="addSurvey.DSSV_Floor"></el-input>
        </el-form-item>
        <el-form-item label="住人情况">
          <el-select v-model="addSurvey.DSSV_LiveStatus" placeholder="请选择">
            <el-option v-for="(value, key, index) in liveStatus" :key="index" :label="value" :value="key"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="距离">
          <el-select v-model="addSurvey.DSSV_Distance" placeholder="请选择">
            <el-option v-for="item in distance" :key="item" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="经度">
          <el-input type="number" v-model="addSurvey.DSSV_Lat"></el-input>
        </el-form-item>
        <el-form-item label="纬度">
          <el-input type="number" v-model="addSurvey.DSSV_Lng"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" v-model="addSurvey.DSSV_Remark"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="addSurveyVis = false">取 消</el-button>
        <el-button type="primary" @click="doCheckSurveyName">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="新增项目阶段" :visible.sync="addProjectStepVis">
      <el-form ref="form" :model="addProjectStep" label-width="140px">
        <el-form-item label="项目阶段名称">
          <el-input v-model="addProjectStep.DSPJS_ProjectStepName"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="addProjectStepVis = false">取 消</el-button>
        <el-button type="primary" @click="doAddProjectStep">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="审核情况" :visible.sync="auditVis">
      <el-steps align-center>
        <el-step :status="auditInfo.infoAudit ? 'success' : 'process'" title="定位信息">
          <template slot="description">
            <div style="margin-top: 10px" v-for="info in auditInfo.infoAuditList" :key="info">
              {{ info.DSSA_CreateDate.split(' ')[0] }}{{ info.USR_Name }}:{{
                info.DSSA_Remark
              }}
            </div>
          </template>
        </el-step>

        <el-step :status="auditInfo.plantAudit ? 'success' : 'process'" title="户型图">
          <template slot="description">
            <div style="margin-top: 10px" v-for="info in auditInfo.plantAuditList" :key="info">
              {{ info.DSSA_CreateDate.split(' ')[0] }}{{ info.USR_Name }}:{{
                info.DSSA_Remark
              }}
            </div>
          </template>
        </el-step>

        <el-step :status="auditInfo.surveyAudit ? 'success' : 'process'" title="勘查信息">
          <template slot="description">
            <div style="margin-top: 10px" v-for="info in auditInfo.surveyAuditList" :key="info">
              {{ info.DSSA_CreateDate.split(' ')[0] }}{{ info.USR_Name }}:{{
                info.DSSA_Remark
              }}
            </div>
          </template>
        </el-step>
      </el-steps>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="auditVis = false">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="新增勘查人员" :visible.sync="addSurveyOpVis">
      <el-form ref="form">
        <el-form-item v-if="!isUpdateSurveyOp" label="勘查人员">
          <el-select style="width: 300px" v-model="selectEmps" filterable remote reserve-keyword placeholder="请输入关键词"
            :remote-method="doGetEmployees" :loading="loading">
            <el-option v-for="item in employees" :key="item.ECV_TargetID" :label="item.USR_Name"
              :value="item.ECV_TargetID">
              {{ item.USR_Name }}
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始勘查">
          <el-date-picker v-model="surveyStartDate" type="date" value-format="yyyy-MM-dd"
            placeholder="选择日期"></el-date-picker>
        </el-form-item>
        <el-form-item label="结束勘查">
          <el-date-picker v-model="surveyEndDate" type="date" value-format="yyyy-MM-dd"
            placeholder="选择日期"></el-date-picker>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="addSurveyOpVis = false">取 消</el-button>
        <el-button type="primary" @click="doAddSurveyOp">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { baseURL,imageServer, tokenName, empIdName } from '@/config'
import {
  GetProject,
  GetProjectSteps,
  AddProjectStep,
  UpdateSurveyOpUser,
  AddSurveyOpUser,
  DeleteSurveyOpUser,
  HasSurveyOp,
} from '@/api/project/project.js'
import {
  AddSurvey,
  GetSurveys,
  GetSurveyListMap,
  ImportBeforeSurveyList,
  ImportAfootSurveyList,
  CheckSurveyName,
  RemoveSurveyStep,
  GetSurveyModifyCount,
  GetSurveyProject,
  GetSurveyList,
  DeleteSurveyList,
  GetSurveyAudits,
  getEmployees
} from '@/api/project/survey.js'
import uploadImageForm from '../components/uploadImage.vue'
import axios from 'axios'

export default {
  components: { uploadImageForm },
  computed: {
    ...mapGetters({
      curEmp: 'user/curEmp',
    }),
  },
  data: function () {
    return {
      prjId: 0,
      project: {},
      uploadType: null,
      fullscreenLoading: false,
      importAllSurveyInfoPath:
        baseURL + '/api/Project/SurveyUpload/ImportAllSurveyInfo',
      UploadCachePath: baseURL + '/api/Project/SurveyUpload/UploadCacheImage',
      uploadListPath: baseURL + '/api/Project/SurveyUpload/ImportSurveyList',
      myHeaders: {},
      importStepID: null,
      projectSteps: {},
      selectSteps: [],
      searchName: null,
      total: 0,
      pageIndex: 1,
      pageSize: 10,
      surveys: [],
      projectStepVis: false,
      addProjectStepVis: false,
      addSurveyOpVis: false,
      isUpdateSurveyOp: false,
      surveyStartDate: null,
      surveyEndDate: null,
      addImgVis: false,
      addSurvey: {},
      addSurveyVis: false,
      addProjectStep: {
        DSPJS_ProjectStepName: '首勘',
      },
      selectListID: 0,
      selectOp: {},
      employees: [],
      loading: false,
      selectEmps: [],
      structures: {
        1: '木瓦',
        2: '砖瓦',
        3: '砖混',
        4: '土瓦',
        5: '石瓦',
        6: '框架',
        7: '其他',
      },
      liveStatus: {
        1: '住人',
        2: '空置',
        3: '其他',
      },

      surveySteps: {
        0: '首勘',
        1: '复勘',
        2: '二次复勘',
      },
      distance: ['50到100米','100到150米','150到200米','200米以上','特殊'],
      activeName: 1,
      tabIndex: 1,
      undoneCount: 0,
      surveyList: [],
      auditVis: false,
      auditInfo: {},
      isInfoNoAudit: false,
      isPlaneNoAudit: false,
      isSurveyNoAudit: false,
      isSurveyMap:false,
      seachEmps:null,
      isMimus: false,
      addSurveyListVis:false,
      surveyStep:1,
      surveyListFiles:[],
      selectEmpId:0

    }
  },
  methods: {
    toSurveyAudit(id) {
      this.GetSurveyAudits(id)
    },
    GetSurveyAudits(id) {
      var that = this

      GetSurveyAudits(id).then((r) => {
        console.log(r)
        that.auditInfo = r.data
        that.$nextTick(() => {
          that.auditVis = true
        })
      })
    },
    GetProject() {
      var that = this

      GetSurveyProject(this.prjId).then((r) => {
        that.project = r.data
        if (that.project.DSSP_HasBefore) {
          that.activeName = 1
        } else {
          if (that.project.DSSP_HasAfoot) {
            that.activeName = 2
          } else {
            that.activeName = 3
          }
        }
        that.doGetProjectSteps()
        that.doGetSurveys()
        that.doGetSurveyList()
      })
    },
    toImport(stepid) {
      this.$router.push({
        path: 'surveyImport',
        query: { id: this.prjId, stepid: this.activeName },
      })
    },
    toSurveyModify() {
      this.$router.push({
        path: 'surveyModify',
        query: { step: this.activeName, prjId: this.prjId },
      })
    },
    doGetProjectSteps() {
      var that = this
      GetProjectSteps(this.prjId).then((r) => {
        that.projectSteps = r.data
        that.selectSteps = r.data.beforeSteps
        if (that.activeName == 1) {
          this.selectSteps = this.projectSteps.beforeSteps
        }
        if (that.activeName == 2) {
          this.selectSteps = this.projectSteps.afootSteps
        }
        if (that.activeName == 3) {
          this.selectSteps = this.projectSteps.afterSteps
        }
      })
    },
    doAddProjectStep() {
      var that = this
      this.addProjectStep.DSPJS_ProjectStep = this.activeName
      this.addProjectStep.DSPJS_ProjectID = this.prjId
      AddProjectStep(this.addProjectStep).then((r) => {
        that.addProjectStepVis = false
        that.addProjectStep = { DSPJS_ProjectStepName: '首勘' }
        that.doGetProjectSteps()
      })
    },
    doDeleteSurveyOpUser(id) {
      var that = this
      that
        .$confirm('确认删除？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
        .then(() => {
          DeleteSurveyOpUser(id).then((r) => {
            that.doGetSurveyList()
          })
        })
        .catch(() => { })
    },
    editSurveyOp(op) {
      var that = this
      this.surveyStartDate = op.DSSOU_StartDate.split(' ')[0]
      this.surveyEndDate = op.DSSOU_EndDate.split(' ')[0]
      this.selectOp = op
      this.isUpdateSurveyOp = true
      this.$nextTick(() => {
        that.addSurveyOpVis = true
      })
    },
    doEditSurveyOp() {
      var that = this
      this.selectOp.DSSOU_StartDate = this.surveyStartDate + ' 00:00:00'
      this.selectOp.DSSOU_EndDate = this.surveyEndDate + ' 23:59:59'

      UpdateSurveyOpUser(this.selectOp).then((r) => {
        that.addSurveyOpVis = false
        that.doGetProjectSteps()
      })
    },
    doGetEmployees(val) {
      if(val.length>1){
        console.log(this.curEmp.EMP_CmpId)
        getEmployees(
          this.curEmp.CCV_TargetID,0, 10,val,this.$store.getters['user/accessToken'],this.$store.getters['user/curEmp'].EMP_ID
        ).then(({ data }) => {
          this.employees = data.Items
          this.loading = false
        })
      }
      
    },
    addSurveyOp() {
      var that = this

      var opList = {
        DSSOU_ListID: that.selectListID,
        DSSOU_UserID: that.selectEmps,
        DSSOU_StartDate: that.surveyStartDate + ' 00:00:00',
        DSSOU_EndDate: that.surveyEndDate + ' 23:59:59',
      }
      AddSurveyOpUser(opList).then((r) => {
        that.addSurveyOpVis = false
        that.doGetSurveyList()
      })
    },
    doAddSurveyOp() {
      var that = this
      if (this.isUpdateSurveyOp) {
        this.doEditSurveyOp()
      } else {
        HasSurveyOp(this.selectEmps, this.prjId).then((r) => {
          if (r.data.hasSurveyOp) {
            that
              .$confirm('该勘查人员有项目正在勘查', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
              })
              .then(() => {
                that.addSurveyOp()
              })
              .catch(() => { })
          } else {
            that.addSurveyOp()
          }
        })
      }
    },
    doImportBeforeSurveyList(step) {
      var that = this
      that
        .$confirm('确认导入施工前花名册？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
        .then(() => {
          ImportBeforeSurveyList(that.prjId, step).then((r) => {
            that.doGetSurveys()
          })
        })
        .catch(() => { })
    },
    doImportAfootSurveyList() {
      var that = this
      that
        .$confirm('确认导入施工中花名册？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
        .then(() => {
          ImportAfootSurveyList(that.prjId).then((r) => {
            that.doGetSurveys()
          })
        })
        .catch(() => { })
    },
    doCheckSurveyName() {
      var that = this
      if (that.addSurvey.DSSV_Name == null || that.addSurvey.DSSV_Name == '') {
        this.$message('请添输入户主姓名')
        return
      }
      CheckSurveyName(
        that.prjId,
        that.activeName,
        that.addSurvey.DSSV_Name
      ).then((r) => {
        if (r.data.isExist) {
          that
            .$confirm(
              '该户主已存在其他施工阶段，确认关联或取消修改户主姓名',
              '提示',
              {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
              }
            )
            .then(() => {
              that.doAddSurvey()
            })
            .catch(() => { })
        } else {
          that.doAddSurvey()
        }
      })
    },

    doGetSurveyModifyCount() {
      GetSurveyModifyCount(this.activeName, this.prjId).then((r) => {
        this.undoneCount = r.data
      })
    },
    doAddSurvey() {
      var that = this
      switch (this.activeName) {
        case 1:
          that.addSurvey.DSSV_HasBefore = true

          break
        case 2:
          that.addSurvey.DSSV_HasAfoot = true
          that.addSurvey.DSSV_IsAfootMinus = that.isMimus
          break
        case 3:
          that.addSurvey.DSSV_HasAfter = true
          that.addSurvey.DSSV_IsAfterMinus
          break
        default:
          break
      }
      that.addSurvey.DSSV_Structure = that.addSurvey.DSSV_Structure.toString()
      that.addSurvey.DSSV_ProjectID = that.prjId
      console.log(that.addSurvey)
      AddSurvey(that.addSurvey).then((r) => {
        that.addSurvey = {}
        that.addSurveyVis = false
        that.doGetSurveys()
      })
    },
    isSurveyMapChange(){
      this.pageIndex=1
      this.doGetSurveys()
    },
    doGetSurveys() {
      console.log(this.seachEmps)
      if(this.isSurveyMap){
        GetSurveyListMap(
          this.prjId,
          this.activeName,
          this.searchName,
          this.pageIndex,
          this.pageSize,
          this.isInfoNoAudit,
          this.isPlaneNoAudit,
          this.isSurveyNoAudit,
          this.selectEmpId
        ).then((r) => {
          this.total = r.data.total
          this.surveys = r.data.datas
        })
      }else{
        GetSurveys(
          this.prjId,
          this.activeName,
          this.searchName,
          this.pageIndex,
          this.pageSize,
          this.isInfoNoAudit,
          this.isPlaneNoAudit,
          this.isSurveyNoAudit
        ).then((r) => {
          this.total = r.data.total
          this.surveys = r.data.datas
        })
      }
      
    },
    doGetSurveyList() {
      var that = this
      GetSurveyList(this.prjId, this.activeName).then((r) => {
        that.surveyList = r.data
      })
    },
    doDeleteSurveyList(id) {
      var that = this
      that
        .$confirm('确认删除？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
        .then(() => {
          DeleteSurveyList(id).then((r) => {
            that.doGetSurveyList()
          })
        })    
        .catch(() => { })
      
    },
    handleListSuccess() {
      this.doGetSurveyList()
      this.doGetSurveys()
    },
    toDetailPage(row) {
      this.$router.push({
        path: 'surveyDetail',
        query: { id: row.DSSV_ID, prjId: row.DSSV_ProjectID },
      })
    },
    handleSuccess() {
      this.fullscreenLoading = false
      this.$refs.upload.clearFiles()
    },
    beforeUpload(file) {
      if (this.importStepID == null) {
        this.$message.error('请选择施工阶段!')
        return false
      }
      if (file.name.split('.')[1] != this.uploadType) {
        this.$message.error('请上传' + this.uploadType + '文件!')
        return false
      }
      if (file.size / 1024 / 1024 > 300) {
        this.$message.error('文件不能超过300M!')
        return false
      }
      this.fullscreenLoading = true
    },
    handleClick(tab, event) {
      this.pageIndex = 1
      this.doGetSurveys()
      this.doGetSurveyList()
      this.tabIndex = tab.name
      if (tab.name == 1) {
        this.selectSteps = this.projectSteps.beforeSteps
      }
      if (tab.name == 2) {
        this.selectSteps = this.projectSteps.afootSteps
      }
      if (tab.name == 3) {
        this.selectSteps = this.projectSteps.afterSteps
      }
    },
    doRemoveSurveyStep(surveyId) {
      var that = this
      that
        .$confirm('确认移除该勘查名单？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
        .then(() => {
          RemoveSurveyStep(surveyId, this.activeName).then((r) => {
            that.$message.success('删除成功!')
            that.doGetSurveys()
          })
        })
        .catch(() => { })
    },
    outputImages(surveyId,name) {
      var config = {
        baseURL,
        headers: {},
        responseType: 'blob',
      }
      var that = this
      this.fullscreenLoading = true;
      config.headers[tokenName] = this.$store.getters['user/accessToken']
      config.headers[empIdName] = this.$store.getters['user/curEmp'].EMP_ID
      axios
        .post(imageServer+'/api/UserApi/File/OutputImagesZip',{surveyId:surveyId,token:this.$store.getters['user/accessToken'],empId:this.$store.getters['user/curEmp'].EMP_ID} , config)
        .then((response) => {
          var blob = new Blob([response.data])
          var downloadElement = document.createElement('a')
          var href = window.URL.createObjectURL(blob) //创建下载的链接
          downloadElement.href = href
          downloadElement.download = name+'图片.zip' //下载后文件名
          document.body.appendChild(downloadElement)
          downloadElement.click() //点击下载
          document.body.removeChild(downloadElement) //下载完成移除元素
          window.URL.revokeObjectURL(href) //释放掉blob对象
          that.fullscreenLoading = false
        })
        .catch((error) => {
          console.log('response: ', error)
        })
    },
    GetRoster() {
      var config = {
        baseURL,
        headers: {},
        responseType: 'blob',
      }
      var that = this
      this.fullscreenLoading = true;
      config.headers[tokenName] = this.$store.getters['user/accessToken']
      config.headers[empIdName] = this.$store.getters['user/curEmp'].EMP_ID
      axios
        .post(baseURL+'/api/project/SurveyStatistics/GetRoster',{prjId:this.prjId} , config)
        .then((response) => {
          var blob = new Blob([response.data])
          var downloadElement = document.createElement('a')
          var href = window.URL.createObjectURL(blob) //创建下载的链接
          downloadElement.href = href
          downloadElement.download = that.project.DSSP_Name+'花名册.xls' //下载后文件名
          document.body.appendChild(downloadElement)
          downloadElement.click() //点击下载
          document.body.removeChild(downloadElement) //下载完成移除元素
          window.URL.revokeObjectURL(href) //释放掉blob对象
          that.fullscreenLoading = false
        })
        .catch((error) => {
          console.log('response: ', error)
        })
  },
  },

  
  created() {
    this.myHeaders[tokenName] = this.$store.getters['user/accessToken']
    this.myHeaders[empIdName] = this.$store.getters['user/curEmp'].EMP_ID
  },
  mounted: function () {
    this.prjId = this.$route.query.id
    this.GetProject()
  },
}
</script>

<style scoped>
.header {
  padding: 20px;
}

.container {
  padding: 20px 10px;
}

.upload {
  margin-right: 15px;
}
</style>
